﻿using System;
using UnityEngine;

public class GameStateMachina : MonoBehaviour
{
    private IGameState currentState;

    private void Update()
    {
        currentState?.LogicUpdata();
    }

    private void FixedUpdate()
    {
        currentState?.PhysicUpdata();
    }

    public void SwitchState(IGameState newState, object parameter = null)
    {
        if (currentState != null)
        {
            StateEventManager.TriggerStateExit();
            currentState.Exit();
        }
        currentState = newState;
        StateEventManager.SetCurrentState(newState);
        StateEventManager.TriggerStateEnter();
        currentState.Enter(parameter); // 传递参数
    }
}
